package ypmits.components.header {
	import ypmits.components.Component;
	import ypmits.components.ComponentSkin;
	import ypmits.components.IComponent;
	import ypmits.components.util.TextFieldUtility;
	import ypmits.font.Arial;
	import ypmits.simpledraw.Square;

	import flash.display.Shape;

	/**
	 * @author Dave Lenz
	 */
	public class Header extends Component implements IComponent {

		private var background_even_color : Shape;
		private var background_gradient_color : Square;
		private var textfieldutil : TextFieldUtility;

		
		
		public function Header( width : Number, height : Number, text : String, themecolor : uint = 0x000000, backgroundcolor : uint = 0x555555 )
		{
			var s : ComponentSkin = new ComponentSkin( );
			s.width = width;
			s.height = height;
			s.text = text;
			s.color = themecolor;
			s.backgroundcolor = backgroundcolor;
			s.rotation = 90;
			
			super( s );
			
			draw( );
		}

		
		
		private function draw() : void 
		{
			var skin : ComponentSkin = ComponentSkin( skin );
			background_gradient_color = new Square( skin.width, skin.height, new Array( skin.color, skin.color ), new Array( 0, 1 ), new Array( 0, 0xFF ), skin.rotation );

			textfieldutil = new TextFieldUtility( skin.text, new Arial().fontName, 16, 0xFFFFFF, true );
			textfieldutil.html = true;
			textfieldutil.x = 6;
			textfieldutil.y = 6;

			addChild( background_even_color = new Shape( ) );
			addChild( background_gradient_color );
			addChild( textfieldutil );
			
			redraw( );
		}

		
		
		private function redraw() : void 
		{
			background_even_color.graphics.clear( );
			background_even_color.graphics.beginFill( skin.backgroundcolor );
			background_even_color.graphics.drawRect( 0, 0, skin.width, skin.height );
			background_even_color.graphics.endFill( );
			
			background_gradient_color.width = skin.width;
		}

		
		
		override public function set width( value : Number ) : void {
			skin.width = value;
			redraw( );
		}

		
		
		override public function set height( value : Number ) : void {
			skin.height = value;
			redraw( );
		}
	}
}
